package fr.mma.livraison.channel.dao;

import java.util.ArrayList;
import java.util.List;

import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.util.DAOBase;

import fr.mma.livraison.channel.persistance.Channel;

public class ChannelDao  extends DAOBase{
	    
	static {
		ObjectifyService.register(Channel.class);
	}

	
    public List<Channel> getAll() {
    	final List<Channel> allChannel = new ArrayList<Channel>();
		for (Channel channel : ofy().query(Channel.class)) {
			allChannel.add(channel);
		} 
		return allChannel;
    }

	public Channel getOrCreate(final long identifiant) {
		Channel found = ofy().find(Channel.class, identifiant);
		if (found == null) {
			found = new Channel(identifiant);
		}
		return found;
	}
    
	public Channel getByClientId(final String identifiant) {
		return ofy().query(Channel.class).filter("channelKeyList in", "identifiant").get();
	}

	public void save(final Channel type) {
		ofy().put(type);
	}
	
	public void delete(final Channel type) {
		ofy().delete(type);
	}
	
	public void delete(final String id) {
		ofy().delete(Channel.class, id);
	}
}
